package schema

import (
	"time"

	modelx "modelx"

	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/index"
)

// User holds the schema definition for the User entity.
type User struct {
	ent.Schema
}

func (User) Indexes() []ent.Index {
	return []ent.Index{
		// 非唯一约束索引
		index.Fields("name"),
		// 唯一约束索引
		//index.Fields().Unique(),
	}
}

// Fields of the User.

// Edges of the User.
func (User) Edges() []ent.Edge {
	return []ent.Edge{edge.To("pets", Pet.Type)}
}

// Fields of the User.
func (User) Fields() []ent.Field {
	return []ent.Field{
		field.Int("age").
			Positive(),
		field.String("name").MaxLen(20).
			Default("unknown"),
		field.Time("time"),
		field.JSON("json", modelx.Std{}),
		field.Time("created_at").
			Default(time.Now),
	}
}
